﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using OpenMms.Common.Auth;
using OpenMms.Domain.Interface.User;
using OpenMms.Domain.RequestModels;
using Microsoft.AspNetCore.Mvc;

namespace OpenMms.MVC.Areas.User.Controllers
{
    /// <summary>
    /// 修改资料
    /// </summary>
    [Area("User")]
    public class ModifyInfoController : BaseController
    {
        #region 注入
        private IHomeService _service;

        private IModifyInfoService _info;

        public ModifyInfoController(IAuth auth, IHomeService service, IModifyInfoService info) : base(auth)
        {
            this._service = service;
            this._info = info;
        }
        #endregion

        #region 首页
        public async Task<IActionResult> Index()
        {
            var sessioninfo = _auth.GetCurrentUser();
            //用户资料
            var userinfo = await _service.GetInfo(sessioninfo.Account);

            return View(userinfo);
        }
        #endregion

        #region 修改资料
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<JsonResult> Modify(ModifyInfoReq req)
        {
            var sessionInfo = _auth.GetCurrentUser();
            req.Code = sessionInfo.Account;
            return Json(await _info.ModifyInfo(req));
        }
        #endregion
    }
}